package com.ruoyi.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysAppKey;
import com.ruoyi.project.system.service.ISysAppKeyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 密钥管理Controller
 * 
 * @author ruoyi
 * @date 2020-04-10
 */
@RestController
@RequestMapping("/system/key")
@Api(tags = "密钥管理")
public class SysAppKeyController extends BaseController
{
    @Autowired
    private ISysAppKeyService sysAppKeyService;

    /**
     * 查询密钥管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:key:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAppKey sysAppKey)
    {
        startPage();
        List<SysAppKey> list = sysAppKeyService.selectSysAppKeyList(sysAppKey);
        return getDataTable(list);
    }

    /**
     * 导出密钥管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:key:export')")
    @Log(title = "密钥管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysAppKey sysAppKey)
    {
        List<SysAppKey> list = sysAppKeyService.selectSysAppKeyList(sysAppKey);
        ExcelUtil<SysAppKey> util = new ExcelUtil<SysAppKey>(SysAppKey.class);
        return util.exportExcel(list, "key");
    }

    /**
     * 获取密钥管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:key:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId)
    {
        return AjaxResult.success(sysAppKeyService.selectSysAppKeyById(appId));
    }

    /**
     * 新增密钥管理
     */
    @PreAuthorize("@ss.hasPermi('system:key:add')")
    @Log(title = "密钥管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAppKey sysAppKey)
    {
        return toAjax(sysAppKeyService.insertSysAppKey(sysAppKey));
    }

    /**
     * 修改密钥管理
     */
    @PreAuthorize("@ss.hasPermi('system:key:edit')")
    @Log(title = "密钥管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAppKey sysAppKey)
    {
        return toAjax(sysAppKeyService.updateSysAppKey(sysAppKey));
    }

    /**
     * 删除密钥管理
     */
    @PreAuthorize("@ss.hasPermi('system:key:remove')")
    @Log(title = "密钥管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds)
    {
        return toAjax(sysAppKeyService.deleteSysAppKeyByIds(appIds));
    }
}
